<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // indexof搜索 数组中的元素是否存在
        // 如果元素存在返回下标，否则返回-1
        let color = ["red", "orange", "yellow", "green", "", "cyan", "blue", "purple"];

        // console.log(color.indexOf("orange")); // 1 
        // console.log(color.indexOf("pink"));  // -1


        // 判断元素是否在数组中
        function is_exist(data, arr) {
            if (arr.indexOf(data) !== -1) {
                return true;
            } else {
                return false;
            }
        }
        console.log(is_exist("green", color));
    </script>
</body>

</html>